import Vue from 'vue'
import VueRouter from 'vue-router'

// fix router 多次跳转到同一路由的报错信息
let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (localtion, resolve, reject) {
    if (reject && reject) {
        originPush.call(this, localtion, resolve, reject);
    } else {
        originPush.call(this, localtion,
            () => {
            }, () => {
            }
        );
    }
}
let originReplace = VueRouter.prototype.replace;

VueRouter.prototype.replace = function (localtion, resolve, reject) {
    if (reject && reject) {
        originReplace.replace(this, localtion, resolve, reject);
    } else {
        originReplace.replace(this, localtion, () => {
        }, () => {
        });
    }
}

Vue.use(VueRouter);

import Home from '@/pages/Home';
import Login from '@/pages/Login';
import Register from '@/pages/Register';
import Search from '@/pages/Search';

export default new VueRouter({
    routes: [
        {
            path: '/',
            redirect: '/home'
        },
        {
            name: 'home',
            path: '/home',
            component: Home,
            meta: {}
        },
        {
            name: 'login',
            path: '/login',
            component: Login
        },
        {
            name: 'register',
            path: '/register',
            component: Register
        },
        {
            name: 'search',
            path: '/search/:keyword?',
            component: Search
        }
    ]
})